<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Penentuan_dosen extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('mdl_penentuan_dosen');
		//$this->output->enable_profiler(TRUE);
	}
	
	function index(){
		$this->load->view('penentuan_dosen');
	}
	
	function getdata(){
		echo $this->mdl_penentuan_dosen->getdata();
	}
	
	function save(){
		# init
		$status = "";
		$result = false;
		$data['pesan_error'] = '';
		
		# get post data
		foreach($_POST as $key => $value){
			$data[$key] = $value;
		}
		
		$data['pesan_error'] = '';
		
		if(isset($data['data'])){
			// validasi
			$cek = false;
			foreach($data['data'] as $row){
				if(isset($row['chk'])){
					$cek = true;
					break;
				}
			}
			
			if($cek){
				if($data['kd_dosen'] != ''){
					$result=$this->mdl_penentuan_dosen->InsertOnDB($data);
				}else{
					$data['pesan_error'] = 'Dosen Harus Diisi!';
				}
			}else{
				$data['pesan_error'] = 'Cek data yang akan diset dosen walinya!';
			}
		}else{
			$data['pesan_error'] = 'Isi data dengan benar';
		}
		
		if($result){
			echo json_encode(array('success'=>true));
		}else{
			echo json_encode(array('msg'=>$data['pesan_error']));
		}
	}
	
}